package com.solution.admin.home.controller;

import io.netty.handler.codec.http.HttpScheme;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.solution.admin.auth.entity.TodoEntity;
import com.solution.admin.home.service.IndexService;
import com.solution.common.constants.PublicStatus;
import com.solution.common.controller.BaseController;

/**
 * 首页查询控制层
 * @author: solin
 * @date: 2018年3月29日 下午3:06:41
 */
@RequestMapping("/indexController")
@Controller("AdminIndexController")
public class IndexController extends BaseController{
	private Logger logger = LoggerFactory.getLogger(IndexController.class);
	
	@Autowired
	private IndexService indexService;
	
	/**
	 * 管理系统首页获取待办信息
	 * @param request
	 * @return
	 * @author: solin
	 * @date: 2018年3月29日 下午3:15:56
	 */
	@RequestMapping("/getTodoList")
	@ResponseBody
	public Map<String, Object> getTodoList(HttpServletRequest request) {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			// 查询待办事项数量
			Map<String, Object> tparam = new HashMap<>();
			List<TodoEntity> todoList = indexService.listTodoList(tparam);
			if (todoList != null && todoList.size() > 0) {
				for (TodoEntity todo : todoList) {
					resultMap.put(todo.getTodoName(), todo.getTodoNum());
				}
			}
			resultMap.put(PublicStatus.RESULT_CODE, 1);
		} catch (Exception e) {
			resultMap.put(PublicStatus.RESULT_CODE, 0);
			logger.error(e.getMessage());
		}
		
		return resultMap;
	}
	
}
